<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>联系电话</title>
<link rel="stylesheet" type="text/css" href="__CSS__/index.css">
</head>
<body>

	<div class="zs_content_con clearfix">
		<div class="zs_content_r zs_content_center">
			<div class="zs_content_r_h zs_content_center_h">
				<h1 class="zs_content_kefu">让客服联系您</h1>
			</div>
			<div class="zs_content_text zs_content_center_text">
				<div class="zs_content_form">
					<form name="contact">
						<div class="zs_content_center_input"><span>姓名：</span><input type="text" id='realname' name='realname' placeholder="请输入姓名"></div>
						<div class="zs_content_center_input"><span>电话：</span><input type="text" id='phone' name='phone' placeholder="请输入电话"></div>
						<p>请填写联系方式，我们将在1-2小时内联系您，为您解答所有疑惑！</p>
						<button id='contact_btn' type='button' name='contact_btn' class="zs_content_center_btn">我要开店</button>
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript" src="__JS__/jquery-1.4.2.min.js"></script>
<script>
	
	$("#contact_btn").click(function(){
		var url = "{:U('Index/process')}"
		var realname = $('#realname').val();
		var phone = $('#phone').val();
		var phone_reg = /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
		
		if(realname == '' || realname == null || realname == undefined){
		msg_alert('请输入你的姓名');
		return false;
			}
		if(phone == '' || phone == null || phone == undefined){
		msg_alert('请输入你的电话');
		return false;
			}
		if(!(phone_reg.test(phone))){
				msg_alert('请输入正确的电话格式');
				return false;
			}
		
		$.ajax({
		url:url,
		data:{realname:realname,phone:phone},
		type:'post',
		success:function(d){
			console.log(d);
			if(d.status === 1){
				msg_alert('提交成功');
			}else if(d.status === 2){
				msg_alert('您已提交过加盟信息');
			}else{
				msg_alert('未成功提交');
			}
		}
	});
});
	
	function msg_alert(msg, callback){
		var div = document.createElement('div');
		div.className = 'mask animation_show';
		div.innerHTML = '<div class="conf"><p>'+msg+'</p><a class="true">确定</a>';
		div.onclick = function(e){
			var tag = e.target || e.srcElement;
			if(tag.className === 'true'){
				typeof callback === 'function' && callback();
				div.parentNode.removeChild(div);
			}
		};
		document.body.appendChild(div);
		div.style.display = 'block';
	}
</script>
	
</body>
</html>